#!/bin/sh
# Script to start multi-user session of MFG/PRO
# <header> 
# CATEGORY: DDT project 
# Please check/change the category above if this script will be used by DGs.
#
# Usage: 
#     ./client.sh [<options>]
#   Options:
#     -px   Start session into Progress editor
#     -rf   Start session into rf AIM session
#     -pcode   Start session with .pcode at start of propath
#
#   Examples:
#     ./client.sh -px    : start from progress editor
#     ./client.sh -rf    : start from rf aim session
#     ./client.sh -pcode : add .p code in front of the propath

# $Id$ 

#********************************* History *************************************
# original author: xwl             code review by: jlu
#
# $Log$
#*******************************************************************************

# tokens:
# &DLC = Progress Directory
# &CLIENT-DB-CONNECT = command line to connect to each db in dbset

#
# Set terminal type.
#
if [ -z "${TERM}" ]
then  
    TERM=ansi;export TERM
fi

stty intr '^c'
DLC=/qad/progress/dlc102b02;export DLC
. $DLC/bin/slib_env
PATH=$DLC/bin:$PATH;export PATH
PROMSGS=$DLC/promsgs;export PROMSGS
PROTERMCAP=$DLC/protermcap;export PROTERMCAP
PS1='$$ ';export PS1
PROPATH=/qad/local/sandbox/user/ysg/01/mrc2012/devsrc,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/config,/qad/mfgpro/93/qadfin_cache/2011.0.79.3/proxysrc,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/pro/com/mfgpro,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/pro,.,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/dist,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/dist/us/bbi,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/dist/us,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/qra/qra.pl,/qad/mfgpro/93/qadfin_cache/2011.0.79.3/proxyobj/proxy.pl,/qad/local/sandbox/team/mrc2012/devsrc,/qad/local/sandbox/team/mrc2012/build/work/config,/qad/local/sandbox/team/mrc2012/build/work/pro/com/mfgpro,/qad/local/sandbox/team/mrc2012/build/work/pro,/qad/local/sandbox/team/mrc2012/build/work/dist,/qad/local/sandbox/team/mrc2012/build/work/dist/us/bbi,/qad/local/sandbox/team/mrc2012/build/work/dist/us,/qad/local/sandbox/team/mrc2012/build/work/qra/qra.pl;export PROPATH





typeset STARTPROG="-p mf.p"
typeset BATCH=""

typeset HASARGS="FALSE"
while [ $# -gt 0 -a "${HASARGS}" != "TRUE" ]; do
   case $1 in
      -px) STARTPROG="";;
      -rf) STARTPROG="-p mfwhex.p";; # start from rf aim session
      -batch) BATCH="-b";;
      -start) shift; STARTPROG="-p $1";;
      -propath) shift; PROPATH="$1";;
      -pcode) UsePCode="TRUE";; # add .p code in front of the propath
      --) HASARGS="TRUE";;
      *) echo "ERROR: Invalid parameter: '$1'."; exit 1;;
   esac
   shift
done

if [ "$UsePCode" = "TRUE" ] ; then
   PROPATH=/qad/local/sandbox/user/ysg/01/mrc2012/devsrc,/qad/mfgpro/93/qadfin_cache/2011.0.79.3/proxysrc,/qad/local/sandbox/user/ysg/01/mrc2012/src,/qad/local/sandbox/user/ysg/01/mrc2012/src/validation,/qad/local/sandbox/user/ysg/01/mrc2012/src/us/bbi,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/config,.,/qad/local/sandbox/user/ysg/01/mrc2012/build/work/qra/qra.pl,/qad/mfgpro/93/qadfin_cache/2011.0.79.3/proxyobj/proxy.pl,/qad/local/sandbox/team/mrc2012/devsrc,/qad/local/sandbox/team/mrc2012/src,/qad/local/sandbox/team/mrc2012/src/validation,/qad/local/sandbox/team/mrc2012/src/us/bbi,/qad/local/sandbox/team/mrc2012/build/work/config,/qad/local/sandbox/team/mrc2012/build/work/qra/qra.pl;export PROPATH
fi

#
# Start MFG/PRO.
# 

# exec $DLC/bin/_progres &DB etc
cd /qad/local/sandbox/user/ysg/01/mrc2012/build/work/reports
QAD_DEV_SCRIPT=/qad/local/scripts/fw_set_workdir
if [ -x $QAD_DEV_SCRIPT ]; then
   NewDir=`$QAD_DEV_SCRIPT /qad/local/sandbox/user/ysg/01/mrc2012`
   if [ $? -ne 0 ]; then
      # Some error was returned. Show user error before proceeding
      echo $NewDir
      sleep 5
   else
      cd $NewDir
   fi
fi

$DLC/bin/_progres -rereadnolock -pf /qad/local/sandbox/user/ysg/01/mrc2012/build/work/config/desktop.pf -cpinternal CP936 -cpstream CP936 $STARTPROG $BATCH "$@"
